import request from '@/axios'
import type { CurdData, TransferListParams, TransferListItem, TransferDetailData } from './types'

export const getListApi = (params: any) => {
  return request.get({ url: '/admin/warehouse', params })
}

export const delListApi = (ids: string[] | number[]): Promise<IResponse> => {
  return request.delete({ url: '/admin/warehouse', data: { ids } })
}

export const getInfoApi = (id: string): Promise<IResponse<CurdData>> => {
  return request.get({ url: '/admin/warehouse/' + id })
}

export const saveDataApi = (data: Partial<CurdData>): Promise<IResponse> => {
  if (data.id) {
    return request.put({ url: '/admin/warehouse', data })
  } else {
    return request.post({ url: '/admin/warehouse', data })
  }
}

export const getWarehouseListApi = (params: any) => {
  return request.get({ url: '/admin/warehouse/select', params })
}

export const getSecondWarehouseListApi = (params: any) => {
  return request.get({ url: '/admin/warehouse/secondWarehouse', params })
}

export const getfirstWarehouseListApi = (params: any) => {
  return request.get({ url: '/admin/warehouse/firstWarehouse', params })
}
export const getEnumListApi = (params: any) => {
  return request.get({ url: '/admin/inventory/fieldEnum', params })
}

export const setSaleStatusApi = (data): Promise<IResponse> => {
  return request.post({ url: 'admin/inventory/sale', data })
}

export const getFieldEnumApi = (params: any) => {
  return request.get({ url: '/admin/warehouse/fieldEnum', params })
}

export const getSelectEnumApi = () => {
  return request.get({ url: '/admin/warehouse/selectEnum' })
}

export const getSearchCityApi = (params) => {
  return request.get({ url: '/admin/warehouse/searchCity', params })
}

export function submitInventoryTransferApi(data: any) {
  return request.post({
    url: '/admin/inventory/transfer',
    data
  })
}

// 获取调拨单列表
export const getTransferListApi = (
  params: TransferListParams
): Promise<
  IResponse<{
    list: TransferListItem[]
    total: number
  }>
> => {
  return request.get({ url: '/admin/inventory/transfer', params })
}

// 获取调拨单详情
export const getTransferDetailApi = (
  id: string | number
): Promise<IResponse<TransferDetailData>> => {
  return request.get({ url: '/admin/inventory/transfer/detail', params: { id } })
}

// 编辑调拨单
export const updateTransferApi = (data: {
  id: number
  company_id: number
  logistics_no: string
  logistics_voucher: string
  ship_date: string
  cost: number
  notes: string
}): Promise<IResponse> => {
  return request.put({ url: '/admin/inventory/transfer', data })
}

//取消调拨
export const cancelTransferApi = (data: any) => {
  return request.post({ url: '/admin/inventory/cancelTransfer', data })
}

//入库
export const warehouseInApi = (data: any) => {
  return request.post({ url: '/admin/inventory/transfer/storage', data })
}

//延期到仓
export const warehouseDelayApi = (data: any) => {
  return request.post({ url: '/admin/inventory/transfer/delay', data })
}

//盘点
export const warehouseCountApi = (params: any) => {
  return request.get({ url: '/admin/inventory_count', params })
}

//盘点发货订单
export const warehouseCountShippedOrderApi = (params: any) => {
  return request.get({ url: '/admin/inventory_count/shipped_order', params })
}

//盘点锁定订单
export const warehouseCountLockOrderApi = (params: any) => {
  return request.get({ url: '/admin/inventory_count/lock_order', params })
}

//盘点总数
export const warehouseCountTotalQtyApi = (params: any) => {
  return request.get({ url: '/admin/inventory_count/total_count', params })
}
